package com.bjesc_b2c.app.appraiset.mvp.model.impl;

import android.content.Context;

import com.bjesc_b2c.app.appraiset.bean.TrackBean;
import com.bjesc_b2c.app.appraiset.bean.WaitTrackBean;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.model.AwaitClueModel;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;
import java.util.List;

import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/8/8.
 */

public class AwaitClueModelImpl implements AwaitClueModel {
    private CallBack callBack;

    public AwaitClueModelImpl(CallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void getClueList(Context context, int page, int type, String keyword,int status) {
        HashMap<String, Object> build = new MapUtil()
                .put("page", page)
                .put("type", type)
                .put("keyword", keyword)
                .put("time_type",status)
                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getFollowList(),
                new BaseSubscriber<TokenBean<WaitTrackBean>>(context) {
                    @Override
                    public void onSuccess(TokenBean<WaitTrackBean> o) {
                        if (callBack != null) {
                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        if (callBack != null) {
                            callBack.loadFailure();
                        }
                    }

                    @Override
                    public void onStart() {
                        if (callBack != null) {
                            callBack.loadStart();
                        }
                    }

                    @Override
                    public void onCompleted() {
                        if (callBack != null) {
                            callBack.loadCompleted();
                        }
                    }
                });
    }

    @Override
    public void getF_ClueList(Context context, int page, int type, String keyword,int status) {
        HashMap<String, Object> build = new MapUtil()
                .put("page", page)
                .put("type", type)
                .put("keyword", keyword)
                .put("status", status)
                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getForwardList(),
                new BaseSubscriber<TokenBean<List<TrackBean>>>(context) {
                    @Override
                    public void onSuccess(TokenBean<List<TrackBean>> o) {
                        if (callBack != null) {
//                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        if (callBack != null) {
                            callBack.loadFailure();
                        }
                    }

                    @Override
                    public void onStart() {
                        if (callBack != null) {
                            callBack.loadStart();
                        }
                    }

                    @Override
                    public void onCompleted() {
                        if (callBack != null) {
                            callBack.loadCompleted();
                        }
                    }
                });

    }

    @Override
    public void getIntentClueList(Context context, int page, int type, String keyword,int status) {
        HashMap<String, Object> build = new MapUtil()
                .put("page", page)
                .put("type", type)
                .put("keyword", keyword)
                .put("time_type", status)


                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getIntentFollowList(),
                new BaseSubscriber<TokenBean<WaitTrackBean>>(context) {
                    @Override
                    public void onSuccess(TokenBean<WaitTrackBean> o) {
                        if (callBack != null) {
                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        if (callBack != null) {
                            callBack.loadFailure();
                        }
                    }

                    @Override
                    public void onStart() {
                        if (callBack != null) {
                            callBack.loadStart();
                        }
                    }

                    @Override
                    public void onCompleted() {
                        if (callBack != null) {
                            callBack.loadCompleted();
                        }
                    }
                });

    }

    @Override
    public void getIntentF_ClueList(Context context, int page, int type, String keyword) {
        HashMap<String, Object> build = new MapUtil()
                .put("page", page)
                .put("type", type)
                .put("keyword", keyword)
                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getIntentForwardList(),
                new BaseSubscriber<TokenBean<List<TrackBean>>>(context) {
                    @Override
                    public void onSuccess(TokenBean<List<TrackBean>> o) {
                        if (callBack != null) {
//                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        if (callBack != null) {
                            callBack.loadFailure();
                        }
                    }

                    @Override
                    public void onStart() {
                        if (callBack != null) {
                            callBack.loadStart();
                        }
                    }

                    @Override
                    public void onCompleted() {
                        if (callBack != null) {
                            callBack.loadCompleted();
                        }
                    }
                });

    }

    public interface CallBack {
        void callback(WaitTrackBean bean);

        void loadStart();

        void loadCompleted();

        void loadFailure();
    }
}
